import 'package:flutter/material.dart';
import 'package:xsdk_flutter/xsdk/framework/base/xsdk_widget_stateful.dart';
import 'package:xsdk_flutter/xsdk/framework/component/select_time/bean/x_bean_select_time.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_color.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_date.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_flutter.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_log.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_number.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_style.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_widget.dart';


class XSelectTimeState extends XState{

  //当前选中
  XBeanSelectTime selectTime;

  List<int> years=[];
  List<int> months=[];
  List<int> days=[];

  List<int> weeks=[];
  List<int> quarters=[];

  List<String> hours=[];
  List<String> mins=[];

  int? startYear;
  int? endYear;
  int yearDefaultCount=6;

  double cupertinoPickerDefaultHeight1=243;
  double cupertinoPickerDefaultHeight2=193;
  double cupertinoPickerDefaultHeight3=300;
  double cupertinoPickerItemHeight=48;

  double menuItemWidth=60;
  double menuItemHeight=33;

  bool isClickMenu2AutoSubmit;//点击二级菜单(今日,昨日,前日...)直接自动确认返回结果
  bool isLimitSelectTimeOver;//是否限制选择超出当前时间范围,即最小时间>当前时间

  bool isShowCustomQuickMenuItems;//是否显示自定义快速按钮(今年,去年)

  int UIMode;//0:日,月,周,季,自定义

  XSelectTimeState(
      {
        required this.selectTime,//XBeanSelectTime();
        this.startYear,
        this.endYear,
        super.isKeepPageState=false,
        this.isClickMenu2AutoSubmit=true,
        this.isLimitSelectTimeOver=false,
        this.isShowCustomQuickMenuItems=true,
        this.UIMode=0,
      }
      );

  FixedExtentScrollController? scrollControllerYear;
  FixedExtentScrollController? scrollControllerMonth;
  FixedExtentScrollController? scrollControllerDay;
  FixedExtentScrollController? scrollControllerWeek;
  FixedExtentScrollController? scrollControllerQuarter;

  FixedExtentScrollController? scrollControllerCustomYear;
  FixedExtentScrollController? scrollControllerCustomMonth;
  FixedExtentScrollController? scrollControllerCustomDay;

  FixedExtentScrollController? scrollControllerStartHour;
  FixedExtentScrollController? scrollControllerStartMin;
  FixedExtentScrollController? scrollControllerEndHour;
  FixedExtentScrollController? scrollControllerEndMin;

  @override
  void onCreate() {
    //init data
    _initYearMonthDayData();

  }


  @override
  Widget onBuild(BuildContext context) {

    //titlebar
    Widget titleBarWidget=_getTitleBarWidget();

    //menuitem
    Widget menuItemWidget=_getMenuItemWidget();


    Widget mainColumnWidget;

    if('时间段'==selectTime.type){
      //
      mainColumnWidget=XWidgetUtils.getLayoutColumn(
          children: [
            titleBarWidget,
            menuItemWidget,
          ]
      );

    }else{
      //menubar
      Widget menuBarWidget=_getMenuBarWidget();
      //
      mainColumnWidget=XWidgetUtils.getLayoutColumn(
          children: [
            titleBarWidget,
            menuBarWidget,
            menuItemWidget,
          ]
      );

    }


    //底部弹框是圆角的,同其一致
    return XWidgetUtils.getXLayoutRoundedRectWithBorder(
        height: 386,
        width: double.infinity,
        backgroundColor: Colors.white,
        borderColor: null,
        radius_topLeft: 15,
        radius_topRight: 15,
        radius_bottomLeft: 0,
        radius_bottomRight: 0,
        child: mainColumnWidget,
    );
  }



  @override
  void onDestroy() {
  }

  @override
  void onStart() {
  }


  @override
  Future<void> updateData({int pageIndex = 1}) async {
  }


  ////////////////////////////////////////////////////

  //menuItem:时间段: 时分
  Widget _getMenuItemIsHourMinWidget(){

    //setState更新UI时重新定位到当前时间段
    for(int i=0;i<hours.length;i++){
      if(hours[i]==selectTime.startHour){
        scrollControllerStartHour=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<mins.length;i++){
      if(mins[i]==selectTime.startMin){
        scrollControllerStartMin=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<hours.length;i++){
      if(hours[i]==selectTime.endHour){
        scrollControllerEndHour=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<mins.length;i++){
      if(mins[i]==selectTime.endMin){
        scrollControllerEndMin=FixedExtentScrollController(initialItem:i);
        break;
      }
    }

    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerStartHour,
                  height: cupertinoPickerDefaultHeight3,
                  itemHeight:cupertinoPickerItemHeight,
                  data: hours,
                  onSelectedItemChanged: (int index){
                    //开始时 拨轮
                    selectTime.startHour=hours[index];
                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerStartMin,
                  height: cupertinoPickerDefaultHeight3,
                  itemHeight:cupertinoPickerItemHeight,
                  data: mins,
                  onSelectedItemChanged: (int index){
                    //开始分 拨轮
                    selectTime.startMin=mins[index];

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getWidgetText('至',style: XStyleUtils.textStyle_000_16(fontWeight: FontWeight.bold)),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerEndHour,
                  height: cupertinoPickerDefaultHeight3,
                  itemHeight:cupertinoPickerItemHeight,
                  data: hours,
                  onSelectedItemChanged: (int index){
                    //结束时 拨轮
                    selectTime.endHour=hours[index];
                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerEndMin,
                  height: cupertinoPickerDefaultHeight3,
                  itemHeight:cupertinoPickerItemHeight,
                  data: mins,
                  onSelectedItemChanged: (int index){
                    //结束分 拨轮
                    selectTime.endMin=mins[index];

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );



    return cupertinoPickerWidget;


  }


  //menuItem:日
  Widget _getMenuItemIsDayWidget(){

    //setState更新UI时重新定位到当前日期
    for(int i=0;i<years.length;i++){
      if(years[i]==selectTime.year){
        scrollControllerYear=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<months.length;i++){
      if(months[i]==selectTime.month){
        scrollControllerMonth=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<days.length;i++){
      if(days[i]==selectTime.day){
        scrollControllerDay=FixedExtentScrollController(initialItem:i);
        break;
      }
    }

    //子bar
    Widget itemBarWidget=XWidgetUtils.getLayoutContainer(
        height: menuItemHeight,
        margin: XWidgetUtils.getEdgeInsets(15, 5, 15, 0),
        child: XWidgetUtils.getLayoutRow(
            children: [
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '今日',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:DateTime.now())['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: DateTime.now());
                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }

                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child: XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '昨日',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    DateTime yesterday=DateTime.now().subtract(const Duration(days: 1));
                    selectTime.year=yesterday.year;
                    if(yesterday.month!=selectTime.month){
                      selectTime.month=yesterday.month;
                      _rebuildDaysData();
                    }
                    selectTime.day=yesterday.day;
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:yesterday)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: yesterday);
                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);

                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '前日',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    DateTime beforeYesterday=DateTime.now().subtract(const Duration(days: 2));
                    selectTime.year=beforeYesterday.year;
                    if(beforeYesterday.month!=selectTime.month){
                      selectTime.month=beforeYesterday.month;
                      _rebuildDaysData();
                    }
                    selectTime.day=beforeYesterday.day;
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:beforeYesterday)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: beforeYesterday);
                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
            ]
        )
    );

    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerYear,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: years,
                  onSelectedItemChanged: (int index){
                    //年拨轮
                    //改为在build中统一处理
                    //scrollControllerYear=FixedExtentScrollController(initialItem:index);
                    selectTime.year=years[index];
                    //XLogUtils.printLog('---currentYear= ${selectTime.year}');
                    if(selectTime.month==2){
                      _rebuildDaysData();

                      if(selectTime.day!>28){
                        if(!XDateUtils.isRunNian(selectTime.year!)){
                          selectTime.day=28;
                          //scrollControllerDay=FixedExtentScrollController(initialItem:27);
                        }else{
                          if(selectTime.day!>29){
                            selectTime.day=29;
                            //scrollControllerDay=FixedExtentScrollController(initialItem:28);
                          }
                        }
                      }
                      //刷新日拨轮
                      setState(() {});
                    }

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerMonth,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: months,
                  onSelectedItemChanged: (int index){
                    //月拨轮
                    //改为在build中统一处理
                    //scrollControllerMonth=FixedExtentScrollController(initialItem:index);
                    selectTime.month=months[index];
                    //XLogUtils.printLog('---currentMonth= ${selectTime.month}');
                    //
                    _rebuildDaysData();

                    //
                    if(selectTime.month==2 && selectTime.day!>28){

                      if(!XDateUtils.isRunNian(selectTime.year!)){
                        selectTime.day=28;
                        //scrollControllerDay=FixedExtentScrollController(initialItem:27);
                      }else{
                        if(selectTime.day!>29){
                          selectTime.day=29;
                          //scrollControllerDay=FixedExtentScrollController(initialItem:28);
                        }
                      }
                    }else if(selectTime.month!=2 && selectTime.day!>30 && !XDateUtils.isMonth31Days(selectTime.month!)){
                      selectTime.day=30;
                    }

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    //刷新日拨轮
                    setState(() {});

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value月',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerDay,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: days,
                  onSelectedItemChanged: (int index){
                    //日拨轮
                    //改为在build中统一处理
                    //scrollControllerDay=FixedExtentScrollController(initialItem:index);
                    selectTime.day=days[index];
                    //XLogUtils.printLog('---currentDay= ${selectTime.day}');
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value日',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );



    return XWidgetUtils.getLayoutColumn(
        children: [
          itemBarWidget,
          cupertinoPickerWidget,
        ]
    );


  }

  //menuItem:自定义
  Widget _getMenuItemIsCustomWidget(){

    //setState更新UI时重新定位到当前日期
    if('开始'==selectTime.customTimeType){
      //开始时间
      if(selectTime.customStartTime!=null){
        DateTime? dateTime=XDateUtils.getDateTimeWithString(selectTime.customStartTime!);

        selectTime.year=dateTime?.year;
        selectTime.month=dateTime?.month;
        selectTime.day=dateTime?.day;
        selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:dateTime)['yearWeek'];
        selectTime.quarter=XDateUtils.getQuarterNumber(date: dateTime);

        for(int i=0;i<years.length;i++){
          if(years[i]==dateTime?.year){
            scrollControllerCustomYear=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
        for(int i=0;i<months.length;i++){
          if(months[i]==dateTime?.month){
            scrollControllerCustomMonth=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
        for(int i=0;i<days.length;i++){
          if(days[i]==dateTime?.day){
            scrollControllerCustomDay=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
      
      }else{
        scrollControllerCustomYear=FixedExtentScrollController(initialItem:0);
        scrollControllerCustomMonth=FixedExtentScrollController(initialItem:0);
        scrollControllerCustomDay=FixedExtentScrollController(initialItem:0);
      }
    }else{
      //结束时间
      if(selectTime.customEndTime!=null){
        DateTime? dateTime=XDateUtils.getDateTimeWithString(selectTime.customEndTime!);

        selectTime.year=dateTime?.year;
        selectTime.month=dateTime?.month;
        selectTime.day=dateTime?.day;
        selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:dateTime)['yearWeek'];
        selectTime.quarter=XDateUtils.getQuarterNumber(date: dateTime);

        for(int i=0;i<years.length;i++){
          if(years[i]==dateTime?.year){
            scrollControllerCustomYear=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
        for(int i=0;i<months.length;i++){
          if(months[i]==dateTime?.month){
            scrollControllerCustomMonth=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
        for(int i=0;i<days.length;i++){
          if(days[i]==dateTime?.day){
            scrollControllerCustomDay=FixedExtentScrollController(initialItem:i);
            break;
          }
        }
      
      }else{
        scrollControllerCustomYear=FixedExtentScrollController(initialItem:0);
        scrollControllerCustomMonth=FixedExtentScrollController(initialItem:0);
        scrollControllerCustomDay=FixedExtentScrollController(initialItem:0);
      }

    }


    List<Widget> listWidgets=[];


    if(isShowCustomQuickMenuItems){
      //子bar
      Widget itemBarWidget=XWidgetUtils.getLayoutContainer(
          height: menuItemHeight,
          margin: XWidgetUtils.getEdgeInsets(15, 5, 15, 0),
          child: XWidgetUtils.getLayoutRow(
              children: [
                XWidgetUtils.getWidgetGestureDetector(
                    child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                        radius_topLeft: 5,
                        radius_topRight: 5,
                        radius_bottomLeft: 5,
                        radius_bottomRight: 5,
                        margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                        width: menuItemWidth,
                        height: menuItemHeight,
                        borderColor: XColorUtils.colorCCCCCC,
                        alignment: Alignment.center,
                        backgroundColor: Colors.white,
                        child: XWidgetUtils.getWidgetText(
                            '上年',
                            style: XStyleUtils.textStyle_666_12()
                        )
                    ),
                    onTap: (){
                      DateTime preYear=DateTime.now().subtract(const Duration(days: 366));
                      selectTime.year=preYear.year;
                      selectTime.month=preYear.month;
                      selectTime.day=preYear.day;
                      _rebuildDaysData();

                      //
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:preYear)['yearWeek'];
                      selectTime.quarter=XDateUtils.getQuarterNumber(date: preYear);
                      //
                      DateTime start=DateTime(selectTime.year!,1,1);
                      DateTime end=DateTime(selectTime.year!,12,31);
                      selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                      selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                      //
                      if(isClickMenu2AutoSubmit){
                        //当前时分秒
                        selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                        Map<String,dynamic> result=selectTime.toJson();
                        XFlutterUtils.finishPage(context);
                        if(widget.resultCallback!=null){
                          widget.resultCallback!(result);
                        }
                      }else{
                        setState(() {});
                      }
                    }
                ),
                XWidgetUtils.getWidgetGestureDetector(
                    child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                        radius_topLeft: 5,
                        radius_topRight: 5,
                        radius_bottomLeft: 5,
                        radius_bottomRight: 5,
                        margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                        width: menuItemWidth,
                        height: menuItemHeight,
                        borderColor: XColorUtils.colorCCCCCC,
                        alignment: Alignment.center,
                        backgroundColor: Colors.white,
                        child: XWidgetUtils.getWidgetText(
                            '本年',
                            style: XStyleUtils.textStyle_666_12()
                        )
                    ),
                    onTap: (){
                      selectTime.year=DateTime.now().year;
                      selectTime.month=DateTime.now().month;
                      selectTime.day=DateTime.now().day;
                      _rebuildDaysData();
                      //
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:DateTime.now())['yearWeek'];
                      selectTime.quarter=XDateUtils.getQuarterNumber(date: DateTime.now());

                      //
                      DateTime start=DateTime(selectTime.year!,1,1);
                      DateTime end=DateTime(selectTime.year!,12,31);
                      selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                      selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                      //
                      if(isClickMenu2AutoSubmit){
                        //当前时分秒
                        selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                        Map<String,dynamic> result=selectTime.toJson();
                        XFlutterUtils.finishPage(context);
                        if(widget.resultCallback!=null){
                          widget.resultCallback!(result);
                        }
                      }else{
                        setState(() {});
                      }
                    }
                ),
              ]
          )
      );

      listWidgets.add(itemBarWidget);
    }

    //开始时间-结束时间
    Widget startEndButtonWidget=XWidgetUtils.getLayoutPadding(
      padding: XWidgetUtils.getEdgeInsets(15, 0, 15, 0),
      child: XWidgetUtils.getLayoutRow(
          children: [
            XWidgetUtils.getWidgetText('开始时间:',style: XStyleUtils.textStyle_666_14()),
            XWidgetUtils.getWidgetButtonText(
                text: selectTime.customStartTime??'请选择开始时间',
                buttonStyle: XStyleUtils.getButtonStyle(
                  fontSize: 14,
                  fontColor: '开始'==selectTime.customTimeType?XColorUtils.color000000:XColorUtils.color999999,
                  textDecoration: TextDecoration.underline,
                ),
                onPressed: (){
                  setState(() {
                    selectTime.customTimeType='开始';
                  });
                }
            ),
            XWidgetUtils.getWidgetText('  结束时间:',style: XStyleUtils.textStyle_666_14()),
            XWidgetUtils.getWidgetButtonText(
                text: selectTime.customEndTime??'请选择结束时间',
                buttonStyle: XStyleUtils.getButtonStyle(
                  fontSize: 14,
                  fontColor: '开始'!=selectTime.customTimeType?XColorUtils.color000000:XColorUtils.color999999,
                  textDecoration: TextDecoration.underline,
                ),
                onPressed: (){
                  setState(() {
                    selectTime.customTimeType='结束';
                  });
                }
            ),
          ]
      ),
    );
    listWidgets.add(startEndButtonWidget);


    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerCustomYear,
                  height: cupertinoPickerDefaultHeight2,
                  itemHeight:cupertinoPickerItemHeight,
                  data: years,
                  onSelectedItemChanged: (int index){
                    //年拨轮
                    //改为在build中统一处理
                    //scrollControllerYear=FixedExtentScrollController(initialItem:index);
                    selectTime.year=years[index];
                    //XLogUtils.printLog('---currentYear= ${selectTime.year}');

                    if(selectTime.month==2){
                      _rebuildDaysData();

                      if(selectTime.day!>28){
                        if(!XDateUtils.isRunNian(selectTime.year!)){
                          selectTime.day=28;
                          //scrollControllerDay=FixedExtentScrollController(initialItem:27);
                        }else{
                          if(selectTime.day!>29){
                            selectTime.day=29;
                            //scrollControllerDay=FixedExtentScrollController(initialItem:28);
                          }
                        }
                      }
                    }

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    if('开始'==selectTime.customTimeType){
                      selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }else{
                      selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }

                    //刷新日拨轮
                    setState(() {});

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerCustomMonth,
                  height: cupertinoPickerDefaultHeight2,
                  itemHeight:cupertinoPickerItemHeight,
                  data: months,
                  onSelectedItemChanged: (int index){
                    //月拨轮
                    //改为在build中统一处理
                    //scrollControllerMonth=FixedExtentScrollController(initialItem:index);
                    selectTime.month=months[index];
                    //XLogUtils.printLog('---currentMonth= ${selectTime.month}');
                    //
                    _rebuildDaysData();

                    //
                    if(selectTime.month==2 && selectTime.day!>28){

                      if(!XDateUtils.isRunNian(selectTime.year!)){
                        selectTime.day=28;
                        //scrollControllerDay=FixedExtentScrollController(initialItem:27);
                      }else{
                        if(selectTime.day!>29){
                          selectTime.day=29;
                          //scrollControllerDay=FixedExtentScrollController(initialItem:28);
                        }
                      }
                    }else if(selectTime.month!=2 && selectTime.day!>30 && !XDateUtils.isMonth31Days(selectTime.month!)){
                      selectTime.day=30;
                    }

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    if('开始'==selectTime.customTimeType){
                      selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }else{
                      selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }

                    //刷新日拨轮
                    setState(() {});

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value月',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerCustomDay,
                  height: cupertinoPickerDefaultHeight2,
                  itemHeight:cupertinoPickerItemHeight,
                  data: days,
                  onSelectedItemChanged: (int index){
                    //日拨轮
                    //改为在build中统一处理
                    //scrollControllerDay=FixedExtentScrollController(initialItem:index);
                    selectTime.day=days[index];
                    //XLogUtils.printLog('---currentDay= ${selectTime.day}');
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    if('开始'==selectTime.customTimeType){
                      selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }else{
                      selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:newDate,format:XDateUtils.formatTimeDefault3);
                    }

                    //
                    setState(() {});

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value日',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );
    listWidgets.add(cupertinoPickerWidget);

    return XWidgetUtils.getLayoutColumn(
        children: listWidgets
    );

  }

  //menuItem:月
  Widget _getMenuItemIsMonthWidget(){

    //setState更新UI时重新定位到当前日期
    for(int i=0;i<years.length;i++){
      if(years[i]==selectTime.year){
        scrollControllerYear=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<months.length;i++){
      if(months[i]==selectTime.month){
        scrollControllerMonth=FixedExtentScrollController(initialItem:i);
        break;
      }
    }

    //子bar
    Widget itemBarWidget=XWidgetUtils.getLayoutContainer(
        height: menuItemHeight,
        margin: XWidgetUtils.getEdgeInsets(15, 5, 15, 0),
        child: XWidgetUtils.getLayoutRow(
            children: [
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '本月',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    //
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:DateTime.now())['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: DateTime.now());
                    //
                    DateTime? start=DateTime(selectTime.year!,selectTime.month!,1);
                    DateTime? end=DateTime(selectTime.year!,selectTime.month!,XDateUtils.getDaysOfMonth(selectTime.year!,selectTime.month!));
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上月',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    //
                    DateTime nowDateTime=DateTime.now();

                    if(nowDateTime.month==1){
                      DateTime pre1Month=DateTime(nowDateTime.year-1, 12, 1);
                      selectTime.year=pre1Month.year;
                      selectTime.month=pre1Month.month;
                      selectTime.day=1;
                    }else{
                      DateTime pre1Month=DateTime(nowDateTime.year, nowDateTime.month - 1, 1);
                      selectTime.year=pre1Month.year;
                      selectTime.month=pre1Month.month;
                      selectTime.day=1;
                    }

                    _rebuildDaysData();
                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    DateTime? start=DateTime(selectTime.year!,selectTime.month!,1);
                    DateTime? end=DateTime(selectTime.year!,selectTime.month!,XDateUtils.getDaysOfMonth(selectTime.year!,selectTime.month!));
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上上月',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    //
                    DateTime nowDateTime=DateTime.now();

                    if(nowDateTime.month==1){
                      DateTime pre2Month=DateTime(nowDateTime.year-1, 11, 1);
                      selectTime.year=pre2Month.year;
                      selectTime.month=pre2Month.month;
                      selectTime.day=1;
                    }else if(nowDateTime.month==2){
                      DateTime pre2Month=DateTime(nowDateTime.year-1, 12, 1);
                      selectTime.year=pre2Month.year;
                      selectTime.month=pre2Month.month;
                      selectTime.day=1;
                    }else{
                      DateTime pre2Month=DateTime(nowDateTime.year, nowDateTime.month - 2, 1);
                      selectTime.year=pre2Month.year;
                      selectTime.month=pre2Month.month;
                      selectTime.day=1;
                    }
                    _rebuildDaysData();
                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    DateTime? start=DateTime(selectTime.year!,selectTime.month!,1);
                    DateTime? end=DateTime(selectTime.year!,selectTime.month!,XDateUtils.getDaysOfMonth(selectTime.year!,selectTime.month!));
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
            ]
        )
    );

    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerYear,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: years,
                  onSelectedItemChanged: (int index){
                    //年拨轮
                    //改为在build中统一处理
                    //scrollControllerYear=FixedExtentScrollController(initialItem:index);
                    selectTime.year=years[index];

                    if(selectTime.month==2){
                      _rebuildDaysData();

                      if(selectTime.day!>28){
                        if(!XDateUtils.isRunNian(selectTime.year!)){
                          selectTime.day=28;
                        }else{
                          if(selectTime.day!>29){
                            selectTime.day=29;
                          }
                        }
                      }
                    }

                    //XLogUtils.printLog('---currentYear= ${selectTime.year}');
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    DateTime? start=DateTime(selectTime.year!,selectTime.month!,1);
                    DateTime? end=DateTime(selectTime.year!,selectTime.month!,XDateUtils.getDaysOfMonth(selectTime.year!,selectTime.month!));
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              flex:2,
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerMonth,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: months,
                  onSelectedItemChanged: (int index){
                    //月拨轮
                    selectTime.month=months[index];
                    selectTime.day=1;
                    _rebuildDaysData();

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    DateTime? start=DateTime(selectTime.year!,selectTime.month!,1);
                    DateTime? end=DateTime(selectTime.year!,selectTime.month!,XDateUtils.getDaysOfMonth(selectTime.year!,selectTime.month!));
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value月',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );


    return XWidgetUtils.getLayoutColumn(
        children: [
          itemBarWidget,
          cupertinoPickerWidget
        ]
    );

  }

  //menuItem:周
  Widget _getMenuItemIsWeekWidget(){

    //setState更新UI时重新定位到当前日期
    for(int i=0;i<years.length;i++){
      if(years[i]==selectTime.year){
        scrollControllerYear=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    for(int i=0;i<weeks.length;i++){
      if(weeks[i]==selectTime.yearWeek){
        scrollControllerWeek=FixedExtentScrollController(initialItem:i);
        break;
      }
    }

    //子bar
    Widget itemBarWidget=XWidgetUtils.getLayoutContainer(
        height: menuItemHeight,
        margin: XWidgetUtils.getEdgeInsets(15, 5, 15, 0),
        child: XWidgetUtils.getLayoutRow(
            children: [
              XWidgetUtils.getWidgetGestureDetector(
                  child: XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '本周',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:DateTime.now())['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: DateTime.now());
                    //
                    Map<String,DateTime> range=XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上周',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    DateTime pre1Week=DateTime.now().subtract(const Duration(days: 7));
                    selectTime.year=pre1Week.year;
                    selectTime.month=pre1Week.month;
                    selectTime.day=pre1Week.day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:pre1Week)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: pre1Week);
                    //
                    Map<String,DateTime> range=XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上上周',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    DateTime pre2Week=DateTime.now().subtract(const Duration(days: 14));
                    selectTime.year=pre2Week.year;
                    selectTime.month=pre2Week.month;
                    selectTime.day=pre2Week.day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:pre2Week)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: pre2Week);
                    //
                    Map<String,DateTime> range=XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),

            ]
        )
    );

    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              flex:1,
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerYear,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: years,
                  onSelectedItemChanged: (int index){
                    //年拨轮
                    //改为在build中统一处理
                    //scrollControllerYear=FixedExtentScrollController(initialItem:index);
                    selectTime.year=years[index];

                    if(selectTime.month==2){
                      _rebuildDaysData();

                      if(selectTime.day!>28){
                        if(!XDateUtils.isRunNian(selectTime.year!)){
                          selectTime.day=28;
                        }else{
                          if(selectTime.day!>29){
                            selectTime.day=29;
                          }
                        }
                      }
                    }

                    //
                    DateTime newDate=DateTime(selectTime.year!,selectTime.month!,selectTime.day!);
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:newDate)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: newDate);
                    //
                    Map<String,DateTime> range=XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    setState(() {});

                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              flex:2,
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerWeek,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: weeks,
                  onSelectedItemChanged: (int index){
                    //周拨轮
                    selectTime.yearWeek=weeks[index];
                    //
                    Map<String,DateTime> range=XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    //
                    selectTime.year=start?.year;
                    selectTime.month=start?.month;
                    selectTime.day=start?.day;
                    _rebuildDaysData();

                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: start);
                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);


                  },
                  itemWidgetBuilder: (dynamic value){

                    Map<String,DateTime> rangeDateTime=XDateUtils.getYearWeekRanges(
                        selectTime.year!,value);
                    DateTime? startDateTime=rangeDateTime['start'];
                    DateTime? endDateTime=rangeDateTime['end'];
                    String startRangeStr=XDateUtils.getStringTimeFormat(dateTime:startDateTime,format: 'MM月dd日');
                    String endRangeStr='';
                    if(endDateTime!.year!=selectTime.year!){
                      endRangeStr=XDateUtils.getStringTimeFormat(dateTime: endDateTime,format: 'yyyy年MM月dd日');
                    }else{
                      endRangeStr=XDateUtils.getStringTimeFormat(dateTime: endDateTime,format: 'MM月dd日');
                    }

                    return XWidgetUtils.getWidgetText('第$value周 ($startRangeStr - $endRangeStr)',style:XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );


    return XWidgetUtils.getLayoutColumn(
        children: [
          itemBarWidget,
          cupertinoPickerWidget
        ]
    );

  }
  //menuItem:季度
  Widget _getMenuItemIsQuarterWidget(){

    //setState更新UI时重新定位到当前日期
    for(int i=0;i<years.length;i++){
      if(years[i]==selectTime.year){
        scrollControllerYear=FixedExtentScrollController(initialItem:i);
        break;
      }
    }
    XLogUtils.printLog('--init, selectTime.quarter=${selectTime.quarter}');

    for(int i=0;i<quarters.length;i++){
      if(quarters[i]==selectTime.quarter){
        XLogUtils.printLog('quarters,i=$i,quarter=${quarters[i]}');
        scrollControllerQuarter=FixedExtentScrollController(initialItem:i);
        break;
      }
    }

    //子bar
    Widget itemBarWidget=XWidgetUtils.getLayoutContainer(
        height: menuItemHeight,
        margin: XWidgetUtils.getEdgeInsets(15, 5, 15, 0),
        child: XWidgetUtils.getLayoutRow(
            children: [
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '本季',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    //
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    _rebuildDaysData();
                    //
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:DateTime.now())['yearWeek'];
                    selectTime.quarter=XDateUtils.getQuarterNumber(date: DateTime.now());
                    //
                    Map<String,DateTime> range=XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),
              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上季',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    //
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    //
                    selectTime.quarter=XDateUtils.getQuarterNumber(date:DateTime.now());
                    if(selectTime.quarter==1){
                      selectTime.quarter=4;
                      selectTime.year=selectTime.year!-1;
                      DateTime? start=XDateUtils.getQuarterRange(selectTime.year!,selectTime.quarter!)['start'];
                      selectTime.month=start?.month;
                      selectTime.day=start?.day;
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    }else{
                      selectTime.quarter=selectTime.quarter!-1;
                      DateTime? start=XDateUtils.getQuarterRange(selectTime.year!,selectTime.quarter!)['start'];
                      selectTime.month=start?.month;
                      selectTime.day=start?.day;
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    }
                    _rebuildDaysData();
                    //
                    Map<String,DateTime> range=XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),

              XWidgetUtils.getWidgetGestureDetector(
                  child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      radius_topLeft: 5,
                      radius_topRight: 5,
                      radius_bottomLeft: 5,
                      radius_bottomRight: 5,
                      margin: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
                      width: menuItemWidth,
                      height: menuItemHeight,
                      borderColor: XColorUtils.colorCCCCCC,
                      alignment: Alignment.center,
                      backgroundColor: Colors.white,
                      child: XWidgetUtils.getWidgetText(
                          '上上季',
                          style: XStyleUtils.textStyle_666_12()
                      )
                  ),
                  onTap: (){
                    selectTime.year=DateTime.now().year;
                    selectTime.month=DateTime.now().month;
                    selectTime.day=DateTime.now().day;
                    selectTime.quarter=XDateUtils.getQuarterNumber(date:DateTime.now());

                    if(selectTime.quarter==2){
                      selectTime.year=selectTime.year!-1;
                      selectTime.quarter=4;
                      //
                      DateTime? start=XDateUtils.getQuarterRange(selectTime.year!,selectTime.quarter!)['start'];
                      selectTime.month=start?.month;
                      selectTime.day=start?.day;
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    }else if(selectTime.quarter==1){
                      selectTime.year=selectTime.year!-1;
                      selectTime.quarter=3;
                      //
                      DateTime? start=XDateUtils.getQuarterRange(selectTime.year!,selectTime.quarter!)['start'];
                      selectTime.month=start?.month;
                      selectTime.day=start?.day;
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];

                    }else{
                      selectTime.quarter=selectTime.quarter!-2;
                      //
                      DateTime? start=XDateUtils.getQuarterRange(selectTime.year!,selectTime.quarter!)['start'];
                      selectTime.month=start?.month;
                      selectTime.day=start?.day;
                      selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    }
                    _rebuildDaysData();
                    //
                    Map<String,DateTime> range=XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                    //
                    if(isClickMenu2AutoSubmit){
                      //当前时分秒
                      selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                      Map<String,dynamic> result=selectTime.toJson();
                      XFlutterUtils.finishPage(context);
                      if(widget.resultCallback!=null){
                        widget.resultCallback!(result);
                      }
                    }else{
                      setState(() {});
                    }
                  }
              ),


            ]
        )
    );

    //拨轮
    Widget cupertinoPickerWidget= XWidgetUtils.getLayoutRow(
        mainAxisAlignment:MainAxisAlignment.center,
        children: [
          XWidgetUtils.getLayoutExpanded(
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerYear,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: years,
                  onSelectedItemChanged: (int index){
                    //年拨轮
                    selectTime.year=years[index];

                    Map<String,DateTime> range=XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    //
                    selectTime.month=start!.month;
                    selectTime.day=start.day;
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];

                    if(selectTime.month==2){
                      _rebuildDaysData();

                      if(selectTime.day!>28){
                        if(!XDateUtils.isRunNian(selectTime.year!)){
                          selectTime.day=28;
                        }else{
                          if(selectTime.day!>29){
                            selectTime.day=29;
                          }
                        }
                      }
                    }

                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('$value',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
          XWidgetUtils.getLayoutExpanded(
              flex:2,
              XWidgetUtils.getWidgetCupertinoPicker(
                  scrollController: scrollControllerQuarter,
                  height: cupertinoPickerDefaultHeight1,
                  itemHeight:cupertinoPickerItemHeight,
                  data: quarters,
                  onSelectedItemChanged: (int index){
                    //季度拨轮
                    selectTime.quarter=quarters[index];

                    Map<String,DateTime> range=XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!);
                    DateTime? start=range['start'];
                    DateTime? end=range['end'];
                    //
                    selectTime.month=start!.month;
                    selectTime.day=start.day;
                    selectTime.yearWeek=XDateUtils.getYearWeekNumber(date:start)['yearWeek'];
                    _rebuildDaysData();
                    //
                    selectTime.customStartTime=XDateUtils.getStringTimeFormat(dateTime:start,format:XDateUtils.formatTimeDefault3);
                    selectTime.customEndTime=XDateUtils.getStringTimeFormat(dateTime:end,format:XDateUtils.formatTimeDefault3);
                  },
                  itemWidgetBuilder: (dynamic value){
                    return XWidgetUtils.getWidgetText('第$value季度',style: XStyleUtils.textStyle_000_18(),maxLines: 1,isChineseWordAddCode:false);
                  }
              )
          ),
        ]
    );


    return XWidgetUtils.getLayoutColumn(
        children: [
          itemBarWidget,
          cupertinoPickerWidget
        ]
    );

  }


  //ok
  Widget _getMenuItemWidget(){
    //
    if('日'==selectTime.type){
      return _getMenuItemIsDayWidget();
    }else if('周'==selectTime.type){
      return _getMenuItemIsWeekWidget();
    }else if('月'==selectTime.type){
      return _getMenuItemIsMonthWidget();
    }else if('季度'==selectTime.type){
      return _getMenuItemIsQuarterWidget();
    }else if('自定义'==selectTime.type){
      return _getMenuItemIsCustomWidget();
    }else if('时间段'==selectTime.type){
      return _getMenuItemIsHourMinWidget();
    }else{
      return XWidgetUtils.getLayoutContainer();
    }

  }

  //ok
  Widget _getTitleBarWidget(){
    return XWidgetUtils.getLayoutContainer(
      height: 48,
      margin: XWidgetUtils.getEdgeInsets(0, 0, 0, 5),
      padding: XWidgetUtils.getEdgeInsets(5, 0, 5, 0),
      child: XWidgetUtils.getLayoutRow(
          children: [
            XWidgetUtils.getWidgetButtonText(
                text: '取消',
                buttonStyle: XStyleUtils.getButtonStyle(fontColor: XColorUtils.color666666,fontSize: 14),
                onPressed: (){
                  XFlutterUtils.finishPage(context);
                }
            ),
            XWidgetUtils.getLayoutExpanded(
                XWidgetUtils.getLayoutCenter(XWidgetUtils.getWidgetText('时间段'==selectTime.type?'选择时间段':'选择时间',style: XStyleUtils.textStyle_000_16(fontWeight: FontWeight.bold)))
            ),
            XWidgetUtils.getWidgetButtonText(
                text: '确定',
                buttonStyle: XStyleUtils.getButtonStyle(fontColor: XColorUtils.appMainColor,fontSize: 14),
                onPressed: (){
                  //返回选中结果

                  if(selectTime.type=='时间段'){

                    int startHour=XNumberUtils.dynamic2int(selectTime.startHour);
                    int startMin=XNumberUtils.dynamic2int(selectTime.startMin);
                    int endHour=XNumberUtils.dynamic2int(selectTime.endHour);
                    int endMin=XNumberUtils.dynamic2int(selectTime.endMin);

                    XLogUtils.printLog('---选择时间段:$startHour:$startMin ~ $endHour:$endMin');

                    //
                    if(startHour>endHour){
                      toast('结束时间不能大于开始时间');
                      return;
                    }else{
                      if(startHour==endHour && startMin>endMin){
                        toast('结束时间不能大于开始时间');
                        return;
                      }
                    }

                  }else{
                    //日,月,周,季,自定义

                    if(selectTime.type=='自定义'){
                      DateTime start=XDateUtils.getDateTimeWithString(selectTime.customStartTime!)!;
                      DateTime end=XDateUtils.getDateTimeWithString(selectTime.customEndTime!)!;
                      if(end.compareTo(start)<0){
                        toast('结束时间不能大于开始时间');
                        return;
                      }
                    }

                      //限制选择超出当前时间范围,即最小时间>当前时间
                    if(isLimitSelectTimeOver){
                      DateTime now=XDateUtils.getDateTimeWithString('${DateTime.now().year}-${XNumberUtils.number2StringFillZero(DateTime.now().month)}-${XNumberUtils.number2StringFillZero(DateTime.now().day)}')!;

                      if(selectTime.type=='日'){
                        DateTime start=XDateUtils.getDateTimeWithString('${selectTime.year}-${XNumberUtils.number2StringFillZero(selectTime.month)}-${XNumberUtils.number2StringFillZero(selectTime.day)}')!;
                        if(start.compareTo(now)>0){
                          toast('选择时间范围不能超过今天');
                          XLogUtils.printLog('---选择时间范围不能超过今天');
                          return;
                        }
                      }else if(selectTime.type=='周'){
                        DateTime start=XDateUtils.getDateTimeWithString(XDateUtils.getStringTimeFormat(dateTime: XDateUtils.getYearWeekRanges(selectTime.year!, selectTime.yearWeek!)['start'], format: XDateUtils.formatTimeDefault3))!;
                        if(start.compareTo(now)>0){
                          toast('选择时间范围不能超过本周');
                          XLogUtils.printLog('---选择时间范围不能超过本周');
                          return;
                        }
                      }else if(selectTime.type=='月'){
                        DateTime start=XDateUtils.getDateTimeWithString('${selectTime.year}-${XNumberUtils.number2StringFillZero(selectTime.month)}-01')!;
                        if(start.compareTo(now)>0){
                          toast('选择时间范围不能超过本月');
                          XLogUtils.printLog('---选择时间范围不能超过本月');
                          return;
                        }
                      }else if(selectTime.type=='季度' || selectTime.type=='季'){
                        DateTime start=XDateUtils.getDateTimeWithString(XDateUtils.getStringTimeFormat(dateTime: XDateUtils.getQuarterRange(selectTime.year!, selectTime.quarter!)['start'], format: XDateUtils.formatTimeDefault3))!;
                        if(start.compareTo(now)>0){
                          toast('选择时间范围不能超过本季');
                          XLogUtils.printLog('---选择时间范围不能超过本季');
                          return;
                        }
                      }else if(selectTime.type=='自定义'){
                        DateTime start=XDateUtils.getDateTimeWithString(selectTime.customStartTime!)!;
                        if(start.compareTo(now)>0){
                          toast('选择时间范围不能超过今天');
                          XLogUtils.printLog('---选择时间范围不能超过今天');
                          return;
                        }
                      }
                    }

                    if(selectTime.type=='自定义' && !isShowCustomQuickMenuItems){
                      //自定义隐藏快捷键,则不支持今年和去年,时间限制为90天
                      DateTime start=XDateUtils.getDateTimeWithString(selectTime.customStartTime!)!;
                      DateTime end=XDateUtils.getDateTimeWithString(selectTime.customEndTime!)!;
                      int days=XDateUtils.getDifferenceDay(start,end);

                      if(days>31){
                        toast('查询日期不可大于31日');
                        return;
                      }
                    }

                  }


                  //输出

                  //当前时分秒
                  selectTime.hourMinSec=XDateUtils.getCurrentTime_String(format: XDateUtils.formatTimeDefault6);
                  //
                  Map<String,dynamic> result=selectTime.toJson();
                  XFlutterUtils.finishPage(context);
                  if(widget.resultCallback!=null){
                    widget.resultCallback!(result);
                  }

                }
            ),
          ]
      ),
    );
  }

  //ok
  Widget _getMenuBarWidget(){
    return XWidgetUtils.getXLayoutRoundedRectWithBorder(
        margin: XWidgetUtils.getEdgeInsets(15, 0, 15, 10),
        height: 38,
        radius_topLeft: 5,
        radius_topRight: 5,
        radius_bottomLeft: 5,
        radius_bottomRight: 5,
        borderColor: XColorUtils.colorCCCCCC,
        alignment: Alignment.center,
        backgroundColor: Colors.white,
        child: XWidgetUtils.getLayoutRow(
            mainAxisAlignment:MainAxisAlignment.center,
            children: [
              XWidgetUtils.getLayoutExpanded(
                  XWidgetUtils.getWidgetButtonText(
                      text: '日',
                      buttonStyle: XStyleUtils.getButtonStyle(
                        fontSize: 14,
                        shape:RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5),
                        ),
                        backgroundColor: '日'==selectTime.type?XColorUtils.appMainColor:XColorUtils.colorTransparency,
                        fontColor: '日'==selectTime.type?XColorUtils.colorFFFFFF:XColorUtils.color000000,
                      ),
                      onPressed: (){
                        setState((){
                          selectTime.type='日';
                        });
                      }
                  )
              ),
              XWidgetUtils.getWidgetDividerVertical(height: 18,marginLeft: 0,marginRight: 0),
              XWidgetUtils.getLayoutExpanded(
                  XWidgetUtils.getWidgetButtonText(
                      text: '周',
                      buttonStyle: XStyleUtils.getButtonStyle(
                        fontSize: 14,
                        shape:RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5),
                        ),
                        backgroundColor: '周'==selectTime.type?XColorUtils.appMainColor:XColorUtils.colorTransparency,
                        fontColor: '周'==selectTime.type?XColorUtils.colorFFFFFF:XColorUtils.color000000,
                      ),
                      onPressed: (){
                        setState((){
                          selectTime.type='周';
                        });
                      }
                  )
              ),
              XWidgetUtils.getWidgetDividerVertical(height: 18,marginLeft: 0,marginRight: 0),
              XWidgetUtils.getLayoutExpanded(
                  XWidgetUtils.getWidgetButtonText(
                      text: '月',
                      buttonStyle: XStyleUtils.getButtonStyle(
                        fontSize: 14,
                        shape:RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5),
                        ),
                        backgroundColor: '月'==selectTime.type?XColorUtils.appMainColor:XColorUtils.colorTransparency,
                        fontColor: '月'==selectTime.type?XColorUtils.colorFFFFFF:XColorUtils.color000000,
                      ),
                      onPressed: (){
                        setState((){
                          selectTime.type='月';
                        });
                      }
                  )
              ),
              XWidgetUtils.getWidgetDividerVertical(height: 18,marginLeft: 0,marginRight: 0),
              XWidgetUtils.getLayoutExpanded(
                  XWidgetUtils.getWidgetButtonText(
                      text: '季度',
                      buttonStyle: XStyleUtils.getButtonStyle(
                        fontSize: 14,
                        shape:RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5),
                        ),
                        backgroundColor: '季度'==selectTime.type?XColorUtils.appMainColor:XColorUtils.colorTransparency,
                        fontColor: '季度'==selectTime.type?XColorUtils.colorFFFFFF:XColorUtils.color000000,
                      ),
                      onPressed: (){
                        setState((){
                          selectTime.type='季度';
                        });
                      }
                  )
              ),
              XWidgetUtils.getWidgetDividerVertical(height: 18,marginLeft: 0,marginRight: 0),
              XWidgetUtils.getLayoutExpanded(
                  XWidgetUtils.getWidgetButtonText(
                      text: '自定义',
                      buttonStyle: XStyleUtils.getButtonStyle(
                        fontSize: 14,
                        shape:RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5),
                        ),
                        backgroundColor: '自定义'==selectTime.type?XColorUtils.appMainColor:XColorUtils.colorTransparency,
                        fontColor: '自定义'==selectTime.type?XColorUtils.colorFFFFFF:XColorUtils.color000000,
                      ),
                      onPressed: (){
                        setState((){
                          selectTime.type='自定义';
                        });
                      }
                  )
              ),
            ]
        )
    );

  }

  ////////////////////////////////

  List<int> _getDays(int year,int month){
    List<int> days=[];
    if(month==2){
      if(XDateUtils.isRunNian(year)){
        for(int i=0;i<29;i++){
          days.add(i+1);
        }
      }else{
        for(int i=0;i<28;i++){
          days.add(i+1);
        }
      }
    }else{
      if(month==1
          ||month==3
          ||month==5
          ||month==7
          ||month==8
          ||month==10
          ||month==12
      ){
        for(int i=0;i<31;i++){
          days.add(i+1);
        }
      }else{
        for(int i=0;i<30;i++){
          days.add(i+1);
        }
      }
    }

    return days;
  }


  //重建日期数据(按当前年月对应的日期)
  void _rebuildDaysData(){
    days.clear();
    days.addAll(_getDays(selectTime.year!, selectTime.month!));
  }


  //初始化年月日数据
  void _initYearMonthDayData(){

    years.clear();
    months.clear();
    quarters.clear();
    weeks.clear();
    hours.clear();
    mins.clear();

    int currentYear=DateTime.now().year;

    //init year
    startYear ??= currentYear-yearDefaultCount;
    endYear ??= currentYear+yearDefaultCount;
    if(startYear!>endYear!){
      startYear = currentYear-yearDefaultCount;
      endYear = currentYear+yearDefaultCount;
    }

    if(selectTime.year!<startYear!){
      years.add(selectTime.year!);
    }

    int yearSize=endYear!-startYear!+1;
    for(int i=0;i<yearSize;i++){
      years.add(startYear!+i);
    }

    if(selectTime.year!>endYear!){
      years.add(selectTime.year!);
    }

    //init month
    for(int i=0;i<12;i++){
      months.add(i+1);
    }

    //init day
    _rebuildDaysData();

    //init weeks quarters
    for(int i=0;i<4;i++){
      quarters.add(i+1);
    }
    int weeksOfYear=XDateUtils.getWeeksOfYear(selectTime.year!);
    for(int i=0;i<weeksOfYear;i++){
      weeks.add(i+1);
    }

    for(int i=0;i<24;i++){
      hours.add(XNumberUtils.number2StringFillZero(i));
    }
    for(int i=0;i<60;i++){
      mins.add(XNumberUtils.number2StringFillZero(i));
    }

  }
}